<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:o="http://omnifaces.org/ui"
      xmlns:of="http://omnifaces.org/functions"
      xmlns:p="http://primefaces.org/ui"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions"
      xmlns:jsf="http://xmlns.jcp.org/jsf">
    <h:head>
    </h:head>

    <h:body>
        <f:metadata>
            <f:viewParam name="redirectPage" value="#{LoginPage.redirectPage}"/>
            <f:viewAction action="#{dataverseSession.updateLocaleInViewRoot}"/>
            <f:viewAction action="#{LoginPage.init}"/>
        </f:metadata>
        <ui:composition template="/dataverse_template.xhtml">
            <ui:param name="pageTitle" value="#{bundle.login} - #{dataverseServiceBean.findRootDataverse().name}"/>
            <ui:param name="showDataverseHeader" value="false"/>
            <ui:param name="showMessagePanel" value="#{true}"/>
            <ui:param name="loginRedirectPage" value="dataverse.xhtml"/>
            <ui:define name="body">
                <ui:fragment rendered="#{LoginPage.listAuthenticationProviders().size() lt 1}">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="alert alert-danger">
                                <h:outputFormat value="#{bundle['authenticationProvidersAvailable.tip']}" escape="false">
                                    <f:param value="&lt;h3&gt;"/>
                                    <f:param value="&lt;/h3&gt;"/>
                                    <f:param value="&lt;br /&gt;"/>
                                </h:outputFormat>
                            </div>
                        </div>
                    </div>
                </ui:fragment>
                <div jsf:id="login-container" class="row">

                    <div class="col-md-12">
                        <div class="col-md-6 col-md-offset-3">
                            <h1><span class="glyphicon glyphicon-log-in" /> #{bundle.login}</h1>

                            <div id="builtinProvider" jsf:rendered="#{LoginPage.authProvider.id == 'builtin'}">
                                <h:form id="loginForm" styleClass="form-horizontal">
                                    <p:focus context="loginForm"/>
                                    <ui:remove>
                                        <ui:fragment rendered="#{LoginPage.multipleProvidersAvailable}">
                                            <div class="form-group text-left">
                                                <label class="col-sm-4 control-label" for="loginSystemSelect">
                                                    #{bundle['login.System']}
                                                </label>
                                                <div class="col-sm-8">
                                                    <h:selectOneMenu id="loginSystemSelect" styleClass="form-control" value="#{LoginPage.credentialsAuthProviderId}">
                                                        <f:selectItems value="#{LoginPage.listCredentialsAuthenticationProviders()}" var="ap"
                                                                       itemLabel="#{ap.title}" itemValue="#{ap.id}" />
                                                        <f:ajax render="@all" listener="#{LoginPage.resetFilledCredentials}"/>
                                                    </h:selectOneMenu>
                                                </div>
                                            </div>
                                        </ui:fragment>
                                    </ui:remove>
                                    <ui:repeat id="credentialsContainer" value="#{LoginPage.filledCredentials}" var="fc" varStatus="fcCount">
                                        <div class="form-group text-left">
                                            <label class="col-sm-4 control-label" for="loginForm:credentialsContainer:#{fcCount.index}:#{fc.credential.secret ? 'sC':'c'}redValue">
                                                #{bundle[fc.credential.key]}
                                            </label>
                                            <div class="col-sm-8">
                                                <h:inputText rendered="#{not fc.credential.secret}" value="#{fc.value}" id="credValue" styleClass="form-control"/>
                                                <p:message rendered="#{not fc.credential.secret}" for="loginForm:credentialsContainer:1:sCredValue" display="text"/>
						<h:inputSecret rendered="#{fc.credential.secret}" value="#{fc.value}" id="sCredValue" styleClass="form-control" autocomplete="off"/><!-- browsers will in general not respect autocomplete="foo", but scanners will still flag it as a potential problem -->
                                                <p:message rendered="#{fc.credential.secret}" for="sCredValue" display="text"/>
                                            </div>
                                        </div>
                                    </ui:repeat>
                                    
                                    <!-- validation -->
                                    <div class="form-group" jsf:rendered="#{LoginPage.requireExtraValidation}">
                                        <div class="col-sm-offset-4 col-sm-8">
                                            <p>
                                                <h:outputText styleClass="highlightBold" value="#{bundle['contact.question']}"/> <span class="glyphicon glyphicon-asterisk text-danger" title="#{bundle.requiredField}"/>
                                            </p>
                                            <h:outputFormat value="#{LoginPage.op1} + #{LoginPage.op2} = "/>
                                            <p:inputText id="messageSum" label="Sum" size="4" value="#{LoginPage.userSum}" converterMessage="#{bundle['contact.sum.converterMessage']}"
                                                         required="#{param['DO_VALIDATION']}" requiredMessage="#{bundle['contact.sum.required']}"
                                                         validatorMessage="#{bundle['contact.sum.invalid']}" validator="#{LoginPage.validateUserSum}">
                                                <f:convertNumber integerOnly="true" type="number"/>
                                            </p:inputText>
                                            <h:message for="messageSum" styleClass="bg-danger text-danger"/>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <div class="col-sm-offset-4 col-sm-9 button-block">
                                            <p:commandButton id="login" styleClass="btn btn-default" value="#{bundle.login}" update="@form,:messagePanel" action="#{LoginPage.login}"/>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-4 col-sm-9">
                                            <a href="passwordreset.xhtml">
                                                #{bundle['login.forgot.text']}
                                            </a>
                                        </div>
                                    </div>
                                </h:form>
                            </div>
                            
                            <div id="remoteProvider" jsf:rendered="#{LoginPage.authProvider.id == 'shib'}">
                                <h:form>
                                    <p class="help-block">
                                        <h:outputFormat value="#{bundle['login.institution.blurb']} " escape="false">
                                            <f:param value="#{settingsWrapper.guidesBaseUrl}"/>
                                            <f:param value="#{systemConfig.guidesVersion}"/>
                                        </h:outputFormat>
                                        <h:outputFormat value="#{bundle['login.institution.support.blurbwithLink']}"  rendered="#{!LoginPage.isShibbolethUseWayFinder()}" escape="false">
                                            <o:param>      
                                                <p:commandLink value="#{settingsWrapper.supportTeamName}" onclick ="clickSupportLink();" >
                                                </p:commandLink>
                                            </o:param>
                                        </h:outputFormat>
                                    </p>
                                    <p class="help-block">
                                        <h:outputFormat value="#{bundle['login.institution.wayfinder.blurb']}" rendered="#{LoginPage.isShibbolethUseWayFinder()}" escape="false">
                                        </h:outputFormat>
                                    </p>
                                </h:form>

                                <div class="form-horizontal">
                                    <div class="form-group text-left">
                                        <label class="col-sm-4 control-label" jsf:rendered="#{!LoginPage.isShibbolethUseWayFinder()}">
                                            #{bundle['auth.providers.title.shib']}
                                        </label>
                                        
                                        <!-- As of v6.7, an instance that uses Shibboleth as part of InCommon can switch to -->
                                        <!-- using the new login workflow that relies on WayFinder and MDQ. -->
                                        <div class="col-sm-8" jsf:rendered="#{LoginPage.isShibbolethUseWayFinder()}">
                                            <h:outputLink styleClass="btn btn-default" value="#{LoginPage.getShibWayfinderRedirect()}">
                                                <h:outputText value="Log In via Your Institution"/>
                                            </h:outputLink>
                                        </div>
                                        <!-- Otherwise the default, workflow that relies on DiscoFeed will be used. -->
                                        <div id="idpSelect" class="col-sm-8" jsf:rendered="#{!LoginPage.isShibbolethUseWayFinder()}">
                                            
                                            <script>
                                                shibRedirectPage = '';
                                                shibLang = "#{facesContext.viewRoot.locale}";
                                                shibLangBundle = {};
                                                shibLangBundle["fatal.divMissing"] = "#{bundle['idp.fatal.divMissing']}";
                                                shibLangBundle["fatal.noXMLHttpRequest"] = "#{bundle['idp.fatal.noXMLHttpRequest']}";
                                                shibLangBundle["fatal.wrongProtocol"] = "#{bundle['idp.fatal.wrongProtocol']}";
                                                shibLangBundle["fatal.wrongEntityId"] = "#{bundle['idp.fatal.wrongEntityId']}";
                                                shibLangBundle["fatal.noData"] = "#{bundle['idp.fatal.noData']}";
                                                shibLangBundle["fatal.loadFailed"] = "#{bundle['idp.fatal.loadFailed']}";
                                                shibLangBundle["fatal.noparms"] = "#{bundle['idp.fatal.noparms']}";
                                                shibLangBundle["fatal.noReturnURL"] = "#{bundle['idp.fatal.noReturnURL']}";
                                                shibLangBundle["fatal.badProtocol"] = "#{bundle['idp.fatal.badProtocol']}";
                                                shibLangBundle["idpPreferred.label"] = "#{bundle['idp.idpPreferred.label']}";
                                                shibLangBundle["idpEntry.label"] = "#{bundle['idp.idpEntry.label']}";
                                                shibLangBundle["idpEntry.NoPreferred.label"] = "#{bundle['idp.idpEntry.NoPreferred.label']}";
                                                shibLangBundle["idpList.label"] = "#{bundle['idp.idpList.label']}";
                                                shibLangBundle["idpList.NoPreferred.label"] = "#{bundle['idp.idpList.NoPreferred.label']}";
                                                shibLangBundle["idpList.defaultOptionLabel"] = "#{bundle['idp.idpList.defaultOptionLabel']}";
                                                shibLangBundle["idpList.showList"] = "#{bundle['idp.idpList.showList']}";
                                                shibLangBundle["idpList.showSearch"] = "#{bundle['idp.idpList.showSearch']}";
                                                shibLangBundle["submitButton.label"] = "#{bundle['idp.submitButton.label']}";
                                                shibLangBundle["helpText"] = "#{bundle['idp.helpText']}";
                                                shibLangBundle["defaultLogoAlt"] = "#{bundle['idp.defaultLogoAlt']}";
                                            </script>
                                            <script src="/resources/js/shib/idpselect_config.js"></script>
                                            <script src="/resources/js/shib/idpselect.js"></script>
                                            <script src="/resources/js/shib/idpselect_style.js"></script>                                        
                                        </div>
                                    </div>
                                </div>

                            </div>
                            <!--ONLY RENDER BUTTON FOR OAUTH PROVIDERS (ORCID, Google, GitHub)-->
                            <div class="form-horizontal" jsf:rendered="#{LoginPage.authProvider.OAuthProvider}">
                                <o:form useRequestURI="true">
                                    <p class="help-block">
                                        <h:outputFormat value="#{bundle['auth.providers.blurb']}" escape="false">
                                            <o:param value="#{LoginPage.authProvider.info.title}"/>
                                            <o:param value="#{settingsWrapper.guidesBaseUrl}"/>
                                            <o:param value="#{systemConfig.guidesVersion}"/>
                                            <o:param>
                                                <p:commandLink value="#{settingsWrapper.supportTeamName}" oncomplete="PF('contactForm').show()" update=":contactDialog" actionListener="#{sendFeedbackDialog.initUserInput}">
                                                    <f:setPropertyActionListener target="#{sendFeedbackDialog.messageSubject}" value=""/>
                                                    <f:setPropertyActionListener target="#{sendFeedbackDialog.recipient}" value="#{null}"/>
                                                    <f:setPropertyActionListener target="#{sendFeedbackDialog.userMessage}" value=""/>
                                                    <f:setPropertyActionListener target="#{sendFeedbackDialog.userEmail}" value=""/>
                                                </p:commandLink>
                                            </o:param>
                                        </h:outputFormat>
                                    </p>
                                </o:form>
                                <div class="form-group text-left">
                                    <div class="col-sm-12">
                                        <h:outputLink styleClass="btn btn-default" value="#{OAuth2Page.linkFor(LoginPage.authProvider.id, LoginPage.redirectPage)}">
                                            <o:importFunctions type="edu.harvard.iq.dataverse.authorization.providers.oauth2.impl.OrcidOAuth2AP" />
                                            <h:graphicImage rendered="#{fn:contains(LoginPage.authProvider.id, 'orcid')}" value="#{OrcidOAuth2AP:getLogo()}" height="16" width="16" alt="#{of:format1(bundle['alt.logo'], bundle['auth.providers.title.orcid'])}"/>
                                            <h:outputText rendered="#{not fn:contains(LoginPage.authProvider.id, 'orcid')}" value="#{LoginPage.getLoginButtonText()}"/>
                                            <h:outputText rendered="#{fn:contains(LoginPage.authProvider.id, 'orcid')}" value=" #{bundle['login.button.orcid']}"/>
                                        </h:outputLink>
                                        <ui:fragment rendered="#{fn:contains(LoginPage.authProvider.id, 'orcid')}">
                                            <p class="help-block small" style="margin-top:1em;">
                                                <h:outputText value="#{bundle['auth.providers.orcid.helpmessage1']}"  escape="false"/>
                                            </p>
                                            <p class="help-block small" style="margin-top:1em;">
                                                <h:outputText value="#{bundle['auth.providers.orcid.helpmessage2']}"  escape="false"/>
                                            </p>
                                        </ui:fragment>
                                    </div>
                                </div>
                            </div>

                            <div id="otherProviders" jsf:rendered="#{LoginPage.listAuthenticationProviders().size() > 1}">
                                <h3>#{bundle['auth.providers.title']}</h3>
                                <h:form>
                                    <ui:repeat value="#{LoginPage.listAuthenticationProviders()}" var="provider">
                                        <p:commandLink rendered="#{provider.id != LoginPage.authProvider.id}" styleClass="btn btn-default" actionListener="#{LoginPage.setAuthProviderById(provider.id)}" update="login-container">
                                            <h:outputText value="#{provider.title}" />
                                        </p:commandLink>
                                    </ui:repeat>
                                </h:form>
                                <div jsf:rendered="#{LoginPage.authProvider.id == 'builtin'}">
                                    <p class="help-block">
                                        <h:outputFormat value="#{bundle['auth.providers.tip']}" escape="false">
                                            <o:param value="#{settingsWrapper.guidesBaseUrl}"/>
                                            <o:param value="#{systemConfig.guidesVersion}"/>
                                        </h:outputFormat>
                                    </p>
                                </div>
                            </div>
                            
                            <div id="signUpLink" jsf:rendered="#{dataverseHeaderFragment.signupAllowed}">
                                <p class="help-block margin-top">
                                    <h:outputFormat value="#{bundle['login.signup.blurb']}" escape="false">
                                        <f:param value="#{dataverseHeaderFragment.getSignupUrl(navigationWrapper.redirectPage)}"/>
                                    </h:outputFormat>
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
            </ui:define>
        </ui:composition>
    </h:body>
</html>
